import pandas as pd
from mlxtend.preprocessing import TransactionEncoder
from mlxtend.frequent_patterns import apriori, association_rules
import matplotlib.pyplot as plt
import networkx as nx

# 读取数据，修正文件名
df = pd.read_excel('20250430/餐厅数据.xlsx')

# 转换菜品数据格式
trsations = df['菜品'].str.split(',').to_list()

# 标准化数据
ts = TransactionEncoder()
te_ary = ts.fit(trsations).transform(trsations)
df_enecoded = pd.DataFrame(te_ary, columns=ts.columns_)

#print(de_enecoded.head)
#使用apriori进行关联规则挖掘
frequent_itemsets = apriori(df_enecoded,min_support=0.1,use_colnames=True)
frequent_itemsets.sort_values(by='s')